package cn.opopopo.design_pattern_learn.行为型.visitor;

// 2. 统计字数的访问者
class WordCountVisitor implements DocumentElementVisitor {
    private int wordCount = 0;
    private int imageCount = 0;
    private int tableCount = 0;

    @Override
    public void visit(TextElement text) {
        String[] words = text.getContent().split("\\s+");
        wordCount += words.length;
    }

    @Override
    public void visit(ImageElement image) {
        imageCount++;
    }

    @Override
    public void visit(TableElement table) {
        tableCount++;
    }

    public int getWordCount() { return wordCount; }
    public int getImageCount() { return imageCount; }
    public int getTableCount() { return tableCount; }
}
